package com.ming;

import java.awt.*;

public class Bg {

    //得分
    static int score = 0;
    //药水数量
    static int waterNum = 2;
    //药水状态
    static boolean waterFlag = false;
    //关卡数
    static int level = 1;
    //所需分数
    static int goal = level*5;

    long startTime;

    long endTime;


    Image bg = Toolkit.getDefaultToolkit().getImage("imgs/bg.jpg");
    Image bg1 = Toolkit.getDefaultToolkit().getImage("imgs/bg1.jpg");
    Image peo = Toolkit.getDefaultToolkit().getImage("imgs/peo.png");
    Image water = Toolkit.getDefaultToolkit().getImage("imgs/water.png");

    //绘制字符串
    public static void drawWord(Graphics g,int size,Color color,String str,int x,int y) {
        g.setColor(color);
        g.setFont(new Font("仿宋",Font.BOLD,size));
        g.drawString(str, x, y);
    }

    void paintSelf(Graphics g)
    {
        g.drawImage(bg1,0,0,null);
        g.drawImage(bg,0,200,null);
        switch (GameWin.state){
            case 0:
                drawWord(g,50,Color.BLACK,"准备开始",270,400);
                break;
            case 1:
                drawWord(g,25,Color.BLACK,"第"+level+"关",30,50);
                g.drawImage(peo,310,50,null);
                drawWord(g,30,Color.BLACK,"目标积分:"+goal,30,100);
                drawWord(g,30,Color.BLACK,"当前积分:"+score,30,150);

                g.drawImage(water,630,70,null);
                drawWord(g,30,Color.BLACK,"*"+waterNum,700,125);
                endTime = System.currentTimeMillis();

                long tim = 20 - (endTime-startTime)/1000;
                drawWord(g,30,Color.BLACK,"时间"+(tim>0?tim:0),500,130);
                break;
            case 2:
                break;
            case 3:
                drawWord(g,80,Color.BLACK,"失败",270,400);
                drawWord(g,80,Color.BLACK,"积分:"+score,220,500);
                break;
            default:
        }

    }

    //返回true表示倒计时完成 false正在倒计时
    boolean gameTime(){
        long tim = (endTime-startTime)/1000;
        if (tim>20){
            return true;
        }
        return false;
    }
}
